import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Location } from '@angular/common';

import { aroAnimation } from '../../../../animation';
import { AccountService } from '../../../../services/account.service';

@Component({
  selector: 'app-code',
  templateUrl: './code.component.html',
  styleUrls: ['./code.component.css'],
  animations: [aroAnimation]
})
export class CodeComponent implements OnInit {

  public num1: number;
  public num2: number;
  public num3: number;
  public num4: number;
  public code: string = '';

  public phone: string = '';

  constructor(private router: Router, private currentRouter: ActivatedRoute, private location: Location,
    private accountService: AccountService
  ) { }

  ngOnInit() {
    this.phone = this.currentRouter.snapshot.params['phone'];

    this.accountService.sendCodeForReset(this.phone).subscribe(res => {
      console.log(res);
    });
  }

  public goBack(): void {
    this.location.back();
  }

  public confirm_onclick(): void {
    this.code = '' + this.num1 + this.num2 + this.num3 + this.num4;
    // console.log(this.code,typeof(this.code),this.code.length);
    if (this.num1 && this.num2 && this.num3 && this.num4) {
      this.accountService.verifyCodeForReset(this.phone, this.code).subscribe(res => {
        console.log(res);
        this.router.navigate(['./content/user']);
      });
    }
  }

}
